﻿/*************************************************************************************
 * 文 件 名:   IHK_RoamingCamSystem
 * 
 * 描    述:   HK_RoamingCam系统层脚本
 * 
 * 版    本：  V1.0
 * 创 建 者：  谭潇杰、京产肠饭
 * 创建时间：  2023/5/3
 * 链   接：  https://gitee.com/JingChanChangFan/hk_-unity-tools
*************************************************************************************/

using QFramework;
using System.Collections.Generic;

namespace HKTools
{
    public enum ViewMode
    {
        RoamView, // 第一人称漫游
        BirdView,  // 鸟瞰俯视
        ThreeDView   // 透视俯视  
    }

    public interface IHK_RoamingCamSystem : ISystem
    {
        // 是否是移动端
        bool IsMobile { get; set; }

        BindableProperty<bool> IsCanRotCam { get; }
        BindableProperty<ViewMode> CurViewMode { get; }

        // 场景中所有的 RoamPoint
        List<HK_Point> points { get; set; }

        // 上一个位移过来的点位
        HK_Point LastPoint { get; set; }

        /// <summary>
        /// 初始化 RoamingCamSystem 系统层，是否为移动端使用
        /// </summary>
        void InitRoamingCamSystem(bool isMobile);

        /// <summary>
        /// 改变 摄像机 模式
        /// </summary>
        void ChangeViewMode(ViewMode viewMode, HK_Point point = null);

        /// <summary>
        /// 切换 第一人称漫游 点位
        /// </summary>
        /// <param name="point"></param>
        void SwitchRoamPoint(HK_Point point);
    }

    public class HK_RoamingCamSystem : AbstractSystem, IHK_RoamingCamSystem
    {
        public bool IsMobile { get; set; }

        public BindableProperty<bool> IsCanRotCam { get; } = new BindableProperty<bool>();

        public BindableProperty<ViewMode> CurViewMode { get; } = new BindableProperty<ViewMode>();

        public List<HK_Point> points { get; set; }

        public HK_Point LastPoint { get; set; }

        protected override void OnInit()
        {
            IsCanRotCam.Value = true;
            CurViewMode.Value = ViewMode.RoamView;
            points = new List<HK_Point>();
        }

        public void InitRoamingCamSystem(bool isMobile)
        {
            IsMobile = isMobile;
        }

        public void ChangeViewMode(ViewMode viewMode, HK_Point point = null)
        {
            switch (viewMode)
            {
                case ViewMode.RoamView:
                    if (point == null)
                    {
                        this.SendEvent(new Event_ChangeToRoamView()
                        {
                            _point = LastPoint == null ? points[0] : LastPoint,
                            //_point = LastPoint,
                            _lastViewMode = CurViewMode.Value
                        }); ;
                    }
                    else
                    {
                        this.SendEvent(new Event_ChangeToRoamView()
                        {
                            _point = point,
                            _lastViewMode = CurViewMode.Value
                        });
                        LastPoint = point;
                    }
                    break;
                case ViewMode.BirdView:
                    IsCanRotCam.Value = false;
                    this.SendEvent<Event_ChangeToBirdView>();
                    break;
                case ViewMode.ThreeDView:
                    IsCanRotCam.Value = false;
                    this.SendEvent(new Event_ChangeToThreeDView()
                    {
                        _lastViewMode = CurViewMode.Value
                    });
                    break;
            }

            CurViewMode.Value = viewMode;
        }

        public void SwitchRoamPoint(HK_Point point)
        {
            IsCanRotCam.Value = false;
            this.SendEvent(new Event_SwitchRoamPoint() { _point = point });
            LastPoint = point;
        }
    }
}